---
title: "Cleaning Pulse of Europe"
---

# Load

```{r}
# load packages
  source("helper-packages.R")

# load country-level surveys
  poe_france_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/france/ZA2222.dta")

  poe_germany_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/germany/ZA2226-27.dta")     

  poe_czech_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/czechoslovakia/ZA2228.dta")     

  poe_hungary_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/hungary/ZA2229.dta")     
  
  poe_poland_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/poland/ZA2230.dta")     

  poe_russia_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/russia/ZA2231.dta")     

  poe_ukraine_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/ukraine/ZA2232.dta")     

  poe_lithuania_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/lithuania/ZA2233.dta")     
    
  poe_bulgaria_raw <- 
    read_dta("../raw-data/y-multi-pulse-of-europe/bulgaria/ZA4974.dta") 
```

# Select relevant vars from each dataframe

```{r}
  poe_france_clean <- 
    poe_france_raw %>% 
    select(
      interview_day = q517a, # day of interview
      interview_month = q517b, # month of interview
      religion = q515, # religion
      sector = q514, # urban/rural
      yob = q505, # year of birth
      education = q503, # education
      gender = q504, # gender
      attitudes_jews = q302b, # feeling about jews
      trust = q401h, # trust
      religiosity = q516 # religiosity
      ) %>% 
    mutate(country = "France")

  # poe_gb_clean <- 
  #   poe_gb_raw NO QUESTION ON RELIGIOUS OUTGROUPS 

  # poe_it_clean <- 
  #   poe_it_raw NO QUESTION ON RELIGIOUS OUTGROUPS 

  # poe_sp_clean <- 
  #   poe_sp_raw # NO QUESTION ON RELIGIOUS OUTGROUPS

  poe_germany_clean <- 
    poe_germany_raw %>% 
    select(
      interview_day = q518a, # day of interview
      interview_month = q518b, # month of interview
      religion = q516, # religion
      sector = q515, # urban/rural
      yob = q506, # year of birth
      education = q504, # education
      gender = q505, # gender
      attitudes_jews = q222c, # feeling about jews
      trust = q402h, # trust
      religiosity = q517 # religiosity
      ) %>% 
    mutate(country = "Germany")
  
  poe_czech_clean <- 
    poe_czech_raw %>% 
    select(
      interview_day = q518a, # day of interview
      interview_month = q518b, # month of interview
      religion = q516, # religion
      sector = q515, # urban/rural
      yob = q506, # year of birth
      education = q504, # education
      gender = q505, # gender
      attitudes_jews = q208d, # feeling about jews
      trust = q402h, # trust
      religiosity = q517 # religiosity
      ) %>% 
    mutate(country = "Czechoslovakia")  

  poe_hungary_clean <-
    poe_hungary_raw %>% 
    select(
      interview_day = q518a, # day of interview
      interview_month = q518b, # month of interview
      religion = q516b, # religion
      sector = q515, # urban/rural
      yob = q506, # year of birth
      education = q504, # education
      gender = q505, # gender
      attitudes_jews = q208c, # feeling about jews
      trust = q402h, # trust
      religiosity = q517 # religiosity
      ) %>% 
    mutate(country = "Hungary")    

  poe_poland_clean <- # all good
    poe_poland_raw %>% 
    select(
      interview_day = q517a, # day of interview
      interview_month = q517b, # month of interview
      religion = q515, # religion
      sector = q514, # urban/rural
      yob = q505, # year of birth
      education = q503, # education
      gender = q504, # gender
      attitudes_jews = q208c, # feeling about jews
      trust = q402h, # trust
      religiosity = q516 # religiosity
      ) %>% 
    mutate(country = "Poland")  
  
  poe_russia_clean <- # all good
    poe_russia_raw %>% 
    select(
      interview_day = q516a, # day of interview
      interview_month = q516b, # month of interview
      religion = q514, # religion
      sector = q513, # urban/rural
      yob = q504, # year of birth
      education = q502, # education
      gender = q503, # gender
      attitudes_jews = q221ad, # feeling about jews [this var done]
      trust = q402h, # trust
      religiosity = q515 # religiosity
      ) %>% 
    mutate(country = "Russia") %>% 
    mutate(interview_day = NA, interview_month = NA) # messy dates, inputting range  
  
  poe_ukraine_clean <- # all good
    poe_ukraine_raw %>% 
    select(
      interview_day = q516a, # day of interview
      interview_month = q516b, # month of interview
      religion = q514, # religion
      sector = q513, # urban/rural
      yob = q504, # year of birth
      education = q502, # education
      gender = q503, # gender
      attitudes_jews = q221ad, # feeling about jews [this var done]
      trust = q402h, # trust
      religiosity = q515 # religiosity
      ) %>% 
    mutate(country = "Ukraine")   
  
  poe_lithuania_clean <- # all good
    poe_lithuania_raw %>% 
    select(
      interview_day = q516a, # day of interview
      interview_month = q516b, # month of interview
      religion = q514, # religion
      sector = q513, # urban/rural
      yob = q504, # year of birth
      education = q502, # education
      gender = q503, # gender
      attitudes_jews = q221be, # feeling about jews [this var done]
      trust = q402h, # trust
      religiosity = q515 # religiosity
      ) %>% 
    mutate(country = "Lithuania")  
  
  poe_bulgaria_clean <- # all good
    poe_bulgaria_raw %>% 
    select(
      interview_day = q518a, # day of interview
      interview_month = q518b, # month of interview
      religion = q516, # religion
      sector = q515, # urban/rural
      yob = q506, # year of birth
      education = q504, # education
      gender = q505, # gender
      attitudes_jews = q208c, # feeling about jews [this var done]
      attitudes_muslims = q208b, # feeling about muslims [this var done]
      trust = q402h, # trust
      religiosity = q517 # religiosity; different phrasing of questions
      ) %>% 
    mutate(country = "Bulgaria") %>% 
    mutate(interview_day = NA, interview_month = NA) # messy dates, inputting range
```

# Stack

```{r}
# stack raw
  stacked_raw <- 
    poe_france_clean %>% 
    bind_rows(poe_germany_clean) %>% 
    bind_rows(poe_czech_clean) %>% 
    bind_rows(poe_hungary_clean) %>% 
    bind_rows(poe_poland_clean) %>% 
    bind_rows(poe_russia_clean) %>% 
    bind_rows(poe_ukraine_clean) %>% 
    bind_rows(poe_lithuania_clean) %>% 
    bind_rows(poe_bulgaria_clean)
```

# Clean data

```{r}
# declare dates
  extra_dates <- 
    tribble(
      ~resp_country_common, ~resp_interview_start_date, ~resp_interview_end_date,
      "Bulgaria", "08 May 91", "16 May 91",  #https://dbk.gesis.org/dbksearch/sdesc2.asp?no=4974&db=e
      "Russia", "01 Apr 91", "30 Apr 91",
      "Germany", "22 Apr 91", "31 May 91",
      "Hungary", "01 May 91", "19 May 91",
      "Poland", "10 May 91", "20 May 91",
      "France", "01 Apr 91", "30 May 91",
      "Ukraine", "10 Apr 91", "06 May 91") %>% # inferred from the non-missing dates (though a number of errors in the Russia entries, so only use the range for this country), e.g. max(stacked_clean$resp_interview_date[stacked_clean$resp_country_common == "France"], na.rm = T)
    mutate(
      resp_interview_start_date = as.Date(resp_interview_start_date, "%d %b %y"),
      resp_interview_end_date = as.Date(resp_interview_end_date, "%d %b %y"))

# clean
  stacked_clean <- 
    stacked_raw %>% 
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Pulse of Europe",
        
      # round number (character vector, title case)  
        resp_round = "",      
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3GssqwD",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person", # the documents state "Oral survey with standardized questionnaire"; somewhat ambiguous   

      # country (character vector; list of countries as written in original source)
        resp_country_original = country,

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = 
          make_date(
            day = interview_day,
            month = interview_month,
            year = 1991)) %>% 
        left_join(extra_dates, by = "resp_country_common") %>% 
        mutate(
          
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        # helpful resource: http://gizemarikan.com/wp-content/uploads/2016/11/BJPOLS-SUPP-APPENDIX.pdf
        resp_religion = 
          case_when(
            resp_country_common == "France" & religion == 1 ~ "Christian",
            resp_country_common == "France" & religion == 2 ~ "Christian",
            resp_country_common == "France" & religion == 3 ~ "Christian",
            resp_country_common == "France" & religion == 4 ~ "Jewish",
            resp_country_common == "France" & religion == 5 ~ "Muslim",
            resp_country_common == "France" & religion == 6 ~ "Buddhist",
            resp_country_common == "France" & religion == 7 ~ "Hindu",
            resp_country_common == "France" & religion == 8 ~ "Other religion",
            
            resp_country_common == "Germany" & religion == 1 ~ "Christian",
            resp_country_common == "Germany" & religion == 2 ~ "Christian",
            resp_country_common == "Germany" & religion == 3 ~ "Jewish",
            resp_country_common == "Germany" & religion == 4 ~ "Muslim",
            resp_country_common == "Germany" & religion == 5 ~ "Buddhist",
            resp_country_common == "Germany" & religion == 6 ~ "Hindu",
            resp_country_common == "Germany" & religion == 7 ~ "Other religion",
            
            resp_country_common == "Czechoslovakia" & religion == 1 ~ "Christian",
            resp_country_common == "Czechoslovakia" & religion == 2 ~ "Christian",
            resp_country_common == "Czechoslovakia" & religion == 3 ~ "Christian",
            resp_country_common == "Czechoslovakia" & religion == 4 ~ NA_character_, # "Czechoslovak"
            resp_country_common == "Czechoslovakia" & religion == 5 ~ "Jewish",
            resp_country_common == "Czechoslovakia" & religion == 0 ~ "Other religion",
            
            resp_country_common == "Hungary" & religion == 1 ~ "Christian",
            resp_country_common == "Hungary" & religion == 2 ~ "Christian",
            resp_country_common == "Hungary" & religion == 3 ~ "Christian",
            resp_country_common == "Hungary" & religion == 4 ~ "Jewish",
            resp_country_common == "Hungary" & religion == 5 ~ "Christian",
            resp_country_common == "Hungary" & religion == 6 ~ "Other religion",
            
            resp_country_common == "Poland" & religion == 1 ~ "Christian",
            resp_country_common == "Poland" & religion == 2 ~ "Christian",
            resp_country_common == "Poland" & religion == 3 ~ "Christian",
            resp_country_common == "Poland" & religion == 4 ~ "Other religion",
            
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 1 ~ "Christian",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 2 ~ "Christian",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 3 ~ "Christian",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 4 ~ "Jewish",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 5 ~ "Muslim",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 6 ~ "Hindu",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 7 ~ "Buddhist",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 8 ~ "Christian", # "Uniat"
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 9 ~ "Christian",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 10 ~ "Other religion",
            
            resp_country_common == "Bulgaria" & religion == 1 ~ "Christian",
            resp_country_common == "Bulgaria" & religion == 2 ~ "Christian",
            resp_country_common == "Bulgaria" & religion == 3 ~ "Christian",
            resp_country_common == "Bulgaria" & religion == 4 ~ "Muslim",
            resp_country_common == "Bulgaria" & religion == 5 ~ "Other religion",
            
            TRUE ~ NA_character_),    

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          case_when(
            resp_country_common == "France" & religion == 1 ~ "Catholic",
            resp_country_common == "France" & religion == 2 ~ "Protestant",
            resp_country_common == "France" & religion == 3 ~ "Orthodox",
            resp_country_common == "France" & religion == 4 ~ "Jewish",
            resp_country_common == "France" & religion == 5 ~ "Muslim",
            resp_country_common == "France" & religion == 6 ~ "Buddhist",
            resp_country_common == "France" & religion == 7 ~ "Hindu",
            resp_country_common == "France" & religion == 8 ~ "Other",
            
            resp_country_common == "Germany" & religion == 1 ~ "Catholic",
            resp_country_common == "Germany" & religion == 2 ~ "Protestant",
            resp_country_common == "Germany" & religion == 3 ~ "Jewish",
            resp_country_common == "Germany" & religion == 4 ~ "Muslim",
            resp_country_common == "Germany" & religion == 5 ~ "Buddhist",
            resp_country_common == "Germany" & religion == 6 ~ "Hindu",
            resp_country_common == "Germany" & religion == 7 ~ "Other",
            
            resp_country_common == "Czechoslovakia" & religion == 1 ~ "Catholic",
            resp_country_common == "Czechoslovakia" & religion == 2 ~ "Protestant (Lutheran)",
            resp_country_common == "Czechoslovakia" & religion == 3 ~ "orthodox",
            resp_country_common == "Czechoslovakia" & religion == 4 ~ NA_character_, # "Czechoslovak"
            resp_country_common == "Czechoslovakia" & religion == 5 ~ "Jewish",
            resp_country_common == "Czechoslovakia" & religion == 0 ~ "Other",
            
            resp_country_common == "Hungary" & religion == 1 ~ "Catholic (Roman or Greek)",
            resp_country_common == "Hungary" & religion == 2 ~ "Reformed (Calvinist)",
            resp_country_common == "Hungary" & religion == 3 ~ "Lutheran",
            resp_country_common == "Hungary" & religion == 4 ~ "Jewish",
            resp_country_common == "Hungary" & religion == 5 ~ "Baptist, Adventist, other",
            resp_country_common == "Hungary" & religion == 6 ~ "Other",
            
            resp_country_common == "Poland" & religion == 1 ~ "Roman Catholic",
            resp_country_common == "Poland" & religion == 2 ~ "Orthodox",
            resp_country_common == "Poland" & religion == 3 ~ "Protestant",
            resp_country_common == "Poland" & religion == 4 ~ "Other",
            
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 1 ~ "Orthodox",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 2 ~ "Catholic",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 3 ~ "Evangelical Christian Baptism",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 4 ~ "Jewish",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 5 ~ "Muslim",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 6 ~ "Hindu",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 7 ~ "Buddhist",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 8 ~ "Uniat",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 9 ~ "Greek Catholic",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & religion == 10 ~ "Other",
            
            resp_country_common == "Bulgaria" & religion == 1 ~ "Christian Orthodox",
            resp_country_common == "Bulgaria" & religion == 2 ~ "Roman Catholic",
            resp_country_common == "Bulgaria" & religion == 3 ~ "Protestant",
            resp_country_common == "Bulgaria" & religion == 4 ~ "Muslim",
            resp_country_common == "Bulgaria" & religion == 5 ~ "Other",
            
            TRUE ~ NA_character_),        

      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        year_of_birth = 
          as.numeric(case_when(
            yob < 91 ~ paste0("19", sprintf("%02d", yob)),
            yob >= 91 ~ paste0("18", sprintf("%02d", yob)),
            TRUE ~ NA_character_)),
    
        resp_age = 1991 - year_of_birth, 
    
        resp_age = 
          ifelse(resp_age < 18, NA, resp_age), # some clear errors with the dates of birth below age 18 
        
        resp_age = as.character(resp_age), #need char age for merging all datasets

      # respondent's education level
        resp_education_original =
          case_when(
            
            resp_country_common == "Germany" & education == 1 ~ "1. Elementary, basic school education (8 years of schooling) without a completed apprenticeship [Primary]",
            resp_country_common == "Germany" & education == 2 ~ "2. Elementary, basic school training (8 years of schooling) with a completed apprenticeship [Primary]",
            resp_country_common == "Germany" & education == 3 ~ "3. Secondary school education without Academic Secondary School Diploma (Abitur) (10 years of polytechnical secondary school (previously known as Intermediate School) [Primary]",
            resp_country_common == "Germany" & education == 4 ~ "4. Academic Secondary School Diploma (Abitur), completion of Technical School (Hochsculreife), completion of Specialized Technical School (12 years of schooling of extended secondary technical school or of academic secondary school) [Primary]",
            resp_country_common == "Germany" & education == 5 ~ "5. University-level studies (university, fine arts academy, technical college studies, including engineering school (Technikum) [College]",
         
            resp_country_common == "Czechoslovakia" & education == 1 ~ "1. Grade school [Primary]", 
            resp_country_common == "Czechoslovakia" & education == 2 ~ "2. Attended high school, did not graduate [Primary]", 
            resp_country_common == "Czechoslovakia" & education == 3 ~ "3. Attended high school, graduated [Primary]", 
            resp_country_common == "Czechoslovakia" & education == 4 ~ "4. College/university [College]", 
            
            resp_country_common == "Hungary" & education == 1 ~ "1. Less than 8 grades [Primary]", # presuming this
            resp_country_common == "Hungary" & education == 2 ~ "2. 8 general grades (higher elementary school) [Primary]",
            resp_country_common == "Hungary" & education == 3 ~ "3. Secondary school (specialized, technical, gymnasium) [Primary]",
            resp_country_common == "Hungary" & education == 4 ~ "4. University [College]",
              
            resp_country_common == "France" & education == 1 ~ "Primary school [Primary]",
            resp_country_common == "France" & education == 2 ~ "Secondary school [Primary]",
            resp_country_common == "France" & education == 3 ~ "Technical or professional [Primary]",
            resp_country_common == "France" & education == 4 ~ "Higher education [College]",
            
            resp_country_common == "Poland" & education == 1 ~ "1. Incomplete elementary [No education]",
            resp_country_common == "Poland" & education == 2 ~ "2. Elementary [Primary]",
            resp_country_common == "Poland" & education == 3 ~ "3. Basic vocational [Primary]",
            resp_country_common == "Poland" & education == 4 ~ "4. Incomplete secondary [Primary]",
            resp_country_common == "Poland" & education == 5 ~ "5. Secondary college prep [Primary]",
            resp_country_common == "Poland" & education == 6 ~ "6. Secondary technical [Primary]",
            resp_country_common == "Poland" & education == 7 ~ "7. Post secondary [Primary]",
            resp_country_common == "Poland" & education == 8 ~ "8. Incomplete higher [Primary]",
            resp_country_common == "Poland" & education == 9 ~ "9. Higher [College]",
            
            resp_country_common == "Bulgaria" & education == 1 ~ "5. Higher [College]", # note, scale reversed in questionnaire
            resp_country_common == "Bulgaria" & education == 2 ~ "4. Semi-higher [Primary]",
            resp_country_common == "Bulgaria" & education == 3 ~ "3. Secondary [Primary]",
            resp_country_common == "Bulgaria" & education == 4 ~ "2. Primary [Primary]",
            resp_country_common == "Bulgaria" & education == 5 ~ "1. Less than primary [No education]",
            
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 1 ~ "1. 7 grades or lower [Primary]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 2 ~ "2. Did not graduate from secondary school [Primary]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 3 ~ "3. Graduated from secondary school [Primary]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 4 ~ "4. Special secondary education [Primary]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 5 ~ "5. Attended higher educational establishment (no less than 3 years of study), did not graduate [Primary]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 6 ~ "6. Higher education [College]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 7 ~ "7. Post-graduate courses/degree [College]",
            resp_country_common %in% c("Russia", "Ukraine", "Lithuania") & education == 8 ~ "8. Scientific degree (candidate, doctor of sciences) [College]",
            
            TRUE ~ NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            gender == 1 ~ 0,
            gender == 2 ~ 1,
            TRUE ~ NA_real_),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            sector == 1 ~ 1, # rural area or village
            sector %in% c(2:3) ~ 0, # small or middle size town, big town, warsaw
            TRUE ~ NA_real_),      

    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: Q302b/Q222c/Q208d/Q208c/Q221ad; QTEXT: I'd like you to rate some different groups of people in (country) according to how you feel about them. For each group, please tell me whether your opinion is very favorable, mostly favorable, mostly unfavorable, or very unfavorable? Jews.; ROPTIONS: 1 = Very favorable [=0] + 2 = Mostly favorable [=0] + 3 = Mostly unfavorable [=1] + Very unfavorable [=1]; TARGET: Jewish; TYPE: Favorability",
      
      # original response (as character vector)
        resp_soc_dist_1_original = as.character(attitudes_jews),
    
      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            attitudes_jews %in% c(1:2) ~ 0,
            attitudes_jews %in% c(3:4) ~ 1,
            TRUE ~ NA_real_),
    
    #########################  
    ### SOCIAL DISTANCE 2 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_2_qinfo = "NUM: Q208b; QTEXT: I'd like you to rate some different groups of people in (country) according to how you feel about them. For each group, please tell me whether your opinion is very favorable, mostly favorable, mostly unfavorable, or very unfavorable? Muslim Bulgarians; ROPTIONS: 1 = Very favorable [=0] + 2 = Mostly favorable [=0] + 3 = Mostly unfavorable [=1] + Very unfavorable [=1]; TARGET: Muslim; TYPE: Favorability",
      
      # original response (as character vector)
        resp_soc_dist_2_original = as.character(attitudes_muslims),       
      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_2_bin_recode = 
          case_when(
            attitudes_muslims %in% c(1:2) ~ 0,
            attitudes_muslims %in% c(3:4) ~ 1,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = "NUM: Q401h/Q402h; QTEXT: Here are some statements on different topics. Please tell me how much you agree or diasgree with each of these statements. Most people in this society are trustworthy.; ROPTIONS: 1 = Completely agree [=0] + 2 = Mostly agree [=0] + 3 = Mostly disagree [=1] + 4 = Completely disagree [=1]",

      # original response (as character vector)
        resp_gentrust_original = 
          dplyr::recode(
            as.character(trust),
            "8" = NA_character_,
            "9" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = 
          case_when(
            trust %in% c(1:2) ~ 0,
            trust %in% c(3:4) ~ 1,
            TRUE ~ NA_real_),    
    
    #########################  
    ##### RELIGIOSITY #######  
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = 
          case_when(
            resp_country_common == "Bulgaria" ~ "NUM: Q517; QTEXT: Do you attend any religious services several times a week, once a week, a few times during the year or never?; ROPTIONS: 1 = Several times a week + 2 = Once a week + 3 = A few times during the year + 4 = Once a year or less often + 5 = Never",
            TRUE ~ "NUM: Q515/Q516/Q517; QTEXT: Apart from weddings and funerals, do you attend any religious services several times a week, once a week, a few times during the year or never?; ROPTIONS: 1 = Several times a week + 2 = Once a week + 3 = A few times during the year + 4 = Once a year or less often + 5 = Never"),
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(religiosity),
            `8` = NA_real_,
            `9` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (5 - resp_religiosity_original)/4
    
    ) %>% 
    select(starts_with("resp_"))
```

# Save data

```{r}
  saveRDS(stacked_clean, "../cleaned-data/y-3-multi-pulse-of-europe.rds")
```